<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/25/025
 * Time: 10:05
 */

namespace App\Controller;




use App\Model\TrendsModel;
use App\Model\UserModel;
use lib\View;

class TrendsController
{
   public function my_trends(){
       $uid=isset($_SESSION['uid'])?$_SESSION['uid']:'';
       $username=isset($_SESSION['username'])?$_SESSION['username']:'';
    // echo $username;exit();
       $user=new UserModel('user','uid');
    // $mytrends=$trend->get(['username'=>$username]);
       $trends= $user->join(['trend'=>'uid'],['trend.uid'=>$uid]);
    // print_r($row);exit();
       return new View('index',['uid'=>$uid,'trends'=>$trends,'username'=>$username]);
   }
   public function add_trends(){
       $trends=$_POST;
      // print_r($trends);exit();
       $tsrcs=$_FILES['tsrc'];
       $trend=new TrendsModel('trend','tid');
       $s=$trend->checkimg($tsrcs);
       $trends['tsrc']=$s;
       $trends['create_at']=date('y-m-d h:i:s',time());
      if($trend->save($trends)){
          echo '<script>alert("添加动态成功");history.back();</script>';
      }
     //  print_r($trends);exit();
   }
    public function new_trends(){
        $uid=isset($_SESSION['uid'])?$_SESSION['uid']:'';
        $username=isset($_SESSION['username'])?$_SESSION['username']:'';
        $user=new UserModel('user','uid');
        $trends=$user->join(['trend'=>'uid']);
        // print_r($trends);exit();
        foreach ($trends as $k=>$v){
            if ($v['uid']==$uid){
                unset($trends[$k]);
            }
        }
       // print_r($trends);exit();
        return new View('index',['trends'=>$trends,'username'=>$username]);
    }
    public function input($name)
    {
        return htmlspecialchars(stripslashes($_REQUEST[$name]));
    }
}